<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const obj = {
            name: 'laowang',
            age: 18,
        }

        // 修改obj的name属性
        Object.defineProperty(obj,'name',{
            value:'laowang',
            writable:false,
            enumerable:false,
            configurable:false
        })
        obj.name = 'lily'
        console.log(obj);

        // getter setter函数(存取器函数)
        Object.defineProperty(obj,'age',{
            get(){
                console.log('获取值');
                return 18
            },
            set(newValue){
                console.log('值更新');
            }
        })

        obj.age ++
    </script>
</body>
</html>